home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / web / aspmaker / setup.exe / %MAINDIR% / src / createvdir.vbs < prev    next >
Encoding:
Text File  |  2003-08-28  |  4.0 KB  |  132 lines

  1. ' ************************************************************
  2. ' Create a new vdir
  3. '
  4. ' Set vBaseName to name of virtual dir you want to publish
  5. '
  6. ' A virtual dir will be created at http://localhost/vBaseName
  7. '
  8. ' Command: createvdir.vbs vName vPath browse
  9. '
  10. ' (C) 2002 e.World Technology Limited for ASPMaker v2.2+
  11. '
  12. ' Oct 5, 2002
  13. '
  14. ' *************************************************************
  15.  
  16. Option Explicit
  17.  
  18. Dim vBasePath,vBaseName,objArgs,browse
  19.  
  20. Set objArgs = WScript.Arguments
  21.  
  22. If objArgs.count =3 Then
  23.     
  24.     vBaseName = objArgs(0)
  25.     vBasePath = objArgs(1)
  26.     browse = CBool(objArgs(2))    
  27.     
  28.     'call to create vDir
  29.     CreateVDir()
  30.     
  31. Else
  32.  
  33.     WScript.Echo "Invalid no. of arguments."
  34.     
  35. End If
  36.  
  37.  
  38. Sub CreateVDir()
  39.  
  40.     Dim vRoot,vBaseDir,webSite
  41.         Dim WshShell, BtnCode
  42.     On Error Resume Next
  43.  
  44.     ' get the local host default web
  45.     Set webSite = GetObject("IIS://localhost/w3svc/1")
  46.     If IsObject(webSite)=False then
  47.         WScript.Echo "Error Code: " & Hex(Err) & " - " & "Unable to locate the Default Web Site. IIS must be installed."        
  48.         Exit Sub
  49.     Else
  50.         'display webSite.name
  51.     End If
  52.  
  53.     ' get the root
  54.     Set vRoot = webSite.GetObject("IIsWebVirtualDir", "Root")
  55.     If (Err <> 0) Then
  56.         WScript.Echo "Error Code: " & Hex(Err) & " - " & "Unable to access root for " & webSite.ADsPath        
  57.         Exit Sub
  58.     Else
  59.         'display vRoot.name
  60.     End If
  61.  
  62.     ' find or create the vBaseName vroot    
  63.     Err.Number = 0 'Clear Error
  64.     Set vBaseDir = GetObject(vRoot.ADsPath & "/" & vBaseName)
  65.     If Err.Number <> 0 Then
  66.         Err.Number = 0 ' Reset Error
  67.         Set vBaseDir = vRoot.Create("IIsWebVirtualDir",vBaseName)        
  68.         vBaseDir.Accessflags = 515
  69.         vBaseDir.AppCreate False
  70.                 vBaseDir.Path = vBasePath
  71.         vBaseDir.SetInfo
  72.         If (Err <> 0) Then
  73.             WScript.Echo "Error Code: " & Hex(Err) & " - " & "Unable to create " & vRoot.ADsPath & "/" & vBaseName                    
  74.             Exit Sub
  75.         Else
  76.             Err = 0                            
  77.                         Set WshShell = WScript.CreateObject("WScript.Shell")                            
  78.                         BtnCode = WshShell.Popup("Virtual directory http://localhost/" & vBaseDir.Name & " created successfully.", 0, "ASPMaker", 0 + 64)                            
  79.                         Select Case BtnCode
  80.                            case 1 if browse then WshShell.Run "http://localhost/" & vBaseDir.Name
  81.                         End Select          
  82.         End if
  83.         Else                
  84.                 Set WshShell = WScript.CreateObject("WScript.Shell")            
  85.                 BtnCode = WshShell.Popup("Virtual directory http://localhost/" & vBaseDir.Name & " already exists. Do you want to delete and create a new one?", 0, "ASPMaker", 4 + 32)                        
  86.                 Select Case BtnCode
  87.                     case 6 ' Yes
  88.                         DeleteVDir vBaseName
  89.                         CreateVDir()
  90.                     case 7 ' No
  91.                         If browse Then WshShell.Run "http://localhost/" & vBaseDir.Name                        
  92.                 End Select                
  93.     End If
  94.     
  95. End Sub
  96.  
  97.  
  98. Sub DeleteVDir(vBaseName)
  99.  
  100.     Dim vRoot,vBaseDir,webSite,WshShell
  101.     On Error Resume Next
  102.  
  103.     ' get the local host default web
  104.     set webSite = GetObject("IIS://localhost/w3svc/1")
  105.     if IsObject(webSite)=False then
  106.         WScript.Echo "Error Code: " & Hex(Err) & " - " & "Unable to locate the Default Web Site.  IIS must be installed and running."
  107.         exit sub
  108.     else
  109.         'display webSite.name
  110.     end if
  111.  
  112.     ' get the root
  113.     set vRoot = webSite.GetObject("IIsWebVirtualDir", "Root")
  114.     If (Err <> 0) Then
  115.         WScript.Echo "Error Code: " & Hex(Err) & " - " & "Unable to access root for " & webSite.ADsPath        
  116.         Exit sub
  117.     else
  118.         'display vRoot.name
  119.     End If
  120.  
  121.    Err.Number = 0 'Clear Error
  122.    Set vBaseDir = GetObject(vRoot.ADsPath & "/" & vBaseName)
  123.    
  124.      If Err.Number = 0 Then 
  125.           vRoot.Delete "IIsWebVirtualDir", vBaseName      
  126.             'If Err = 0 Then
  127. '                    Set WshShell = WScript.CreateObject("WScript.Shell")
  128. '                    WshShell.Popup "Virtual directory http://localhost/" & vBaseName & " deleted successfully.", 10, "ASPMaker", 0 + 64                    
  129. '            End If
  130.      End If
  131.         
  132. End Sub